import 'package:flutter/material.dart';

import 'dart:async';

class SampleDialogDemo extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => SampleDialogDemoState();
}

enum Option { A, B, C }

class SampleDialogDemoState extends State<SampleDialogDemo> {
  Option option;

  Future _sampleDialog() async {
    final sampleDialog = await showDialog(
        context: context,
        builder: (BuildContext context) => SimpleDialog(
              title: Text('SimpleDialog'),
              children: <Widget>[
                SimpleDialogOption(
                  onPressed: () {
                    Navigator.of(context).pop(Option.A);
                  },
                  child: Text('Option A'),
                ),
                SimpleDialogOption(
                  onPressed: () {
                    Navigator.of(context).pop(Option.B);
                  },
                  child: Text('Option B'),
                ),
                SimpleDialogOption(
                  onPressed: () {
                    Navigator.of(context).pop(Option.C);
                  },
                  child: Text('Option C'),
                )
              ],
            ));

    if (sampleDialog == null) return;

    switch (sampleDialog) {
      case Option.A:
        setState(() {
          option = Option.A;
        });
        break;
      case Option.B:
        setState(() {
          option = Option.B;
        });
        break;
      case Option.C:
        setState(() {
          option = Option.C;
        });
        break;
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('SampleDialogDemo'),
          elevation: 0.0,
        ),
        body: Container(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Text('sample dialog choice value = $option')
                ],
              )
            ],
          ),
        ),
        floatingActionButton: FloatingActionButton(onPressed: _sampleDialog));
  }
}
